import Feature from 'ol/Feature'
import Circle from 'ol/geom/Circle'

export function circle (opts) {
  const { radius, center, fill, id = uuidv4() } = opts
  if (!radius) {
    throw Error('未传入radius参数')
  }
  if (!(center instanceof Array)) {
    throw Error('绘制circle传入中心点坐标格式错误')
  }
  const circle = new Feature({
    id,
    type: 'circle',
    radius,
    fill,
    property: { ...opts },
    geometry: new Circle(center, radius)
  })
  return {
    features: [circle],
    data: [id]
  }
}

export function addCircle (opts) {
  const { features, data } = circle(opts)
  this.addLayer(features)
}